package com.ace3l.legal.gwt.domainmodule.domainxform;

import com.ace3l.legal.gwt.domainmodule.gwt.GWTProject;
import com.ace3l.legal.gwt.domainmodule.gwt.GWTStudent;
import com.ace3l.legal.backend.domain.Project;
import com.ace3l.legal.backend.domain.Student;

import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;
import java.util.HashSet;

/**
 * Created by IntelliJ IDEA.
 * User: ageer
 * Date: Jul 26, 2008
 * Time: 5:31:45 AM
 * To change this template use File | Settings | File Templates.
 */
public class ProjectXForm {
    public static Project fromGWT(GWTProject in) {
        if (in == null) return null;
        Project out = new Project();
        out.setDescription(in.getDescription());
        out.setDueDate(in.getDueDate());
        out.setHoursAllotted(in.getHoursAllotted());
        out.setHoursCompleted(in.getHoursCompleted());
        out.setId(in.getId());
        out.setLawFirm(LawFirmXForm.fromGWT(in.getLawFirm()));
        out.setTitle(in.getTitle());
        out.setWorkflowStage(in.getWorkflowStage());

        Iterator<GWTStudent> it = in.getAssignedStudents().iterator();
        while (it.hasNext()) {
            out.addAssignedStudent(StudentXForm.fromGWT(it.next()));
        }
        return out;
    }
    public static GWTProject toGWT(Project in) {
        if (in == null) return null;
        GWTProject out = new GWTProject();
        out.setDescription(in.getDescription());
        out.setDueDate(in.getDueDate());
        out.setHoursAllotted(in.getHoursAllotted());
        out.setHoursCompleted(in.getHoursCompleted());
        out.setId(in.getId());
        out.setLawFirm(LawFirmXForm.toGWT(in.getLawFirm()));
        out.setTitle(in.getTitle());
        out.setWorkflowStage(in.getWorkflowStage());

        Iterator<Student> it = in.getAssignedStudents().iterator();
        while (it.hasNext()) {
            out.addAssignedStudent(StudentXForm.toGWT(it.next()));
        }
        return out;
    }

    public static List<GWTProject> toGWTList(List<Project> in) {
        Iterator<Project> it = in.iterator();
        List<GWTProject> out = new ArrayList<GWTProject>();
        while (it.hasNext()) {
            out.add(toGWT(it.next()));
        }
        return out;
    }
}
